const { ccclass, } = cc._decorator;

@ccclass
export default class Game extends cc.Component {

    start() {

        //支持一个字段，默认为score

        //setTimeout是为了在开发者工具里设置时序
        setTimeout(() => {
            wx.login({
                success: function () {
                    wx.getUserInfo({
                        withCredentials: true,
                        success: res => {
                            //初始化，传入avatarUrl,在开放数据域识别哪个是自己
                            wx.postMessage({
                                cmd: 'init',
                                url: res.userInfo.avatarUrl
                            })
                        }
                    })
                }
            })

            //上报分数API
            setTimeout(() => {
                wx.postMessage({
                    cmd: 'set',
                    score: Math.floor(Math.random() * 10000)
                })
            }, 1000);
        }, 2000);
    }
}
